<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input type="text" name="item"  autocomplete="off" placeholder="请输入项目名称" class="layui-input">
						</div>
						<div class="layui-input-inline">
							<select id="op_account_id"  lay-search=""  lay-verify="required" autocomplete="off">
								<option value="">直接选择账户ID</option>
								{volist name="account" id='acc'}
									<option value="{$acc.id}" >{$acc.name_id}</option>
								{/volist}
					        </select>
						</div>
						<div class="layui-input-inline">
							<select id="types"  lay-verify="required" autocomplete="off">
								<option value="">选择项目类型</option>
								<option value="1">跑消耗</option>
								<option value="2">跑表单</option>
					        </select>
						</div>
						<div class="layui-input-inline">
							<select id="operate_id"  lay-search=""  lay-verify="required" autocomplete="off">
								<option value="">直接选择运营</option>
								{volist name="userlist" id='u'}
									<option value="{$u.id}" >{$u.username}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<button type="button" class="layui-btn layui-btn-primary"  onclick="get_seek()"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-success layui-btn-sm data-add-btn" lay-event="items">添加项目</button>
			</div>
		</script>
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
		
		<script type="text/html" id="currentTableBar"> 
			<a style="{{d.op_account_id?'':'display:none;'}}{{d.is_finish==0?'':'display:none'}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="end">项目结束</a>
			<a class="layui-btn layui-btn-xs layui-btn-normal " lay-event="consume">消耗记录</a>
		</script>
		<script type="text/html" id="yunying_type">
			<span style="{{d.operate_type == 1?'':'display:none;'}}">自运营</span>
			<span style="{{d.operate_type == 2?'':'display:none;'}}">代运营</span>
			<span style="{{d.operate_type == 3?'':'display:none;'}}">纯代运营</span>
			<span style="{{d.operate_type == 4?'':'display:none;'}}">代充值</span>
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__static/js/man.js" charset="utf-8"></script>
<script>
//添加项目
function add_items(){
	layer.open({
        type: 2,
        title:'添加项目',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('items_add')}"
    });
    //layer.full(index);
}

//添加消耗
function get_consume(items_id,op_account_id){
	var index = layer.open({
        type: 2,
        title:'添加消耗',
        area: ['50%', '60%'],
        offset: ['10%', '5%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('Operate/consume_add')}?items_id="+items_id+'&op_account_id='+op_account_id,
        
    });
    //layer.full(index);
}
//修改消耗
function get_save(id){
	layer.open({
        type: 2,
        title:'修改消耗',
        area: ['50%', '70%'],
        offset: ['10%', '5%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('Operate/save_consume')}?id="+id
    });
    //layer.full(index);
}
//消耗记录
function get_consumes(items_id,op_account_id){
	layer.open({
        type: 2,
        id:'consumes_info',
        title:'消耗记录',
        area: ['40%', '100%'],
        offset: 'r',
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('consume_list')}?items_id="+items_id+'&op_account_id='+op_account_id,
        cancel: function(index, layero){ 
        	get_load();
        	} 
    });
    //layer.full(index);
}
	var $,form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		pageLoading();
		table.render({
			elem: '#currentTableId',
			id:'yy_item_list',
			height: 'full-150',
			url: '{:url("yy_item_list")}?t=json',
			method : 'post',
			toolbar: '#toolbarDemo',
			loading:false,
			cols: [[
				{ field: 'name',fixed: 'left', title: '项目名称',width:160 },
				{ field: 'name_id',fixed: 'left', title: '账户(ID)',width:160,templet: function(d){
			          return d.name_id?d.name_id:''
			    }},
                { field: 'channel_name', title: '端口',width:120},
                { field: 'industry_name', title: '行业',width:80},
                { field: 'customer_name', title: '客户',width:120},
			    { field: 'yesterday_currency', title: '昨日消耗',width:120,sort: true,templet: function(d){
			          return d.yesterday_currency?d.yesterday_currency:'0.00'
			    }},
			    { field: 'total_money', title: '总消耗',width:120,sort: true},
			    
			    { field: 'is_finish', title: '是否结束',width:100,templet: function(d){
			          return d.is_finish==0?'<span class="layui-badge layui-bg-gray">否</span>':'<span class="layui-badge">是</span>'
			    }},
			    { field: 'type', title: '项目类型',width:"120",templet: function(d){
			          return d.type==1?'跑消耗':'跑表单'
				}},
				{ field: 'operate_type', title: '运营类型',width:"120", templet:'#yunying_type'},
			    { field: 'note', title: '备注',width:200},
			    { field: 'operate_name', title: '运营',width:180},
			    { title: '操作', minWidth: 200, fixed: 'right', toolbar: '#currentTableBar',align:'center'}
			]],
			limit: 30,
			page: true,
			skin: 'line',
			done: function () {
                // 添加分页加载动画的函数    
                $('.layui-laypage > a').each(function(){
                    $(this).attr('onclick',"pageLoading(this)");
                })
                layer.close(loadingIndex);
            }
		});
		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'items':
					add_items();
				break;
			}
			
		});
		
		/**
		 * 操作监听事件
		 */
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'end':
					//项目结束
					layer.confirm('您确认要结束项目吗？', {
		                btn: ['确认', '取消'] //按钮
		            }, function () {
		            	
		            	layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
						$.post("{:url('get_today_is_consume')}?t=json",{items_id:data.id},function(da){
							layer.closeAll();
							if(da['code'] == 1){
								layer.msg(da['msg'], { icon : 6 });
							}else{
							 	layer.msg('请添加今天的消耗', { icon : 5 });
							}
						}); 
		            });
				break;
				case 'consume':
					get_consumes(data.id,data.op_account_id);
				break;
			}
			
		});
		

	});
	function get_load(msg=0){
		pageLoading();
		table.reload('yy_item_list', {
			  url: '{:url("yy_item_list")}?t=json',
			});
		if(msg){
			layer.msg(msg, {icon: 6});
		}
		
	}
	function get_seek(){
		pageLoading();
		var name = $("input[name=item]").val();
		var op_account_id = $("#op_account_id").val();
		var type = $("#types").val();
		var operate_id = $('#operate_id').val();
		table.reload('yy_item_list', {
			  url: '{:url("yy_item_list")}?t=json',
			  where:{name:name,op_account_id:op_account_id,type:type,operate_id:operate_id}
			});
	}
	///刷新消耗记录页面
	function get_consume_list(){
		var frameId=document.getElementById('consumes_info').getElementsByTagName('iframe')[0].id;
    	$('#'+frameId)[0].contentWindow.get_load();
	}
</script>

</body>
</html>